/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import entities.Event;
import java.io.IOException;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

/**
 *
 * @author Trong Nguyen
 */
//@ManagedBean
//@ApplicationScoped
public class Uility implements Serializable {

    public static int getAge(Date date) {
        int age = 0;
        Calendar cal = Calendar.getInstance();
        int currentYear = cal.get(Calendar.YEAR);
        cal.setTime(date);
        int bithdayYear = cal.get(Calendar.YEAR);
        age = currentYear - bithdayYear;
        return age;
    }
     public static Date maxDOB(){
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.YEAR, -18);
        return cal.getTime();
    }
     public static Date minDOB(){
         Calendar cal = Calendar.getInstance();
         cal.add(Calendar.YEAR, -60);
         return cal.getTime();
     }
    public static void redirectPage(FacesContext context, Event event, String destinationPage) {

        if (null != event && null != context) {
            try {
                context.getExternalContext().redirect(destinationPage);
            } catch (IOException ex) {
//                Logger.getLogger(Uility.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
